import {useStore} from 'vuex'
import { onShow } from '@dcloudio/uni-app'
import { computed } from "vue";
export const usePermission = ()=>{
	const store = useStore()
	const userInfo = computed(()=>{
		return store.state.user.userInfo
	})
	onShow(()=>{
		if(userInfo.value) return
		uni.showModal({
			title:'登录后访问购物车',
			content:'请登录以便为您提供VIP服务',
			cancelText:'稍后再说',
			confirmText:'立即登录',
			confirmColor:'brown',
			success: ({confirm}) => {
				if(confirm){
					uni.navigateTo({
						url:'/pages/login/index'
					})
				}else{
					uni.switchTab({
						url:'/pages/home/home'
					})
				}
			}
		})
	})
	return {
		userInfo,
		onShow
	}
}